/**   
 * @Title: AbstarctServiceHander.java 
 * @Package com.org.net.tcp 
 * @Description: TODO(用一句话描述该文件做什么) 
 * @author cssuger@163.com   
 * @date 2017年2月9日 下午1:34:46 
 * @version V1.0   
 */
package com.bicon.base.data.common.net.tcp;

import io.netty.bootstrap.Bootstrap;
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;

/** 
 *@ClassName: AbstarctServiceHander 
 *@Description: TODO(这里用一句话描述这个类的作用) 
 *@author cssuger@163.com 
 *@date 2017年2月9日 下午1:34:46  
 */
public abstract class AbstarctServiceHander extends AbstarctClient{

	private String host;
	
	private int port;
	
	public AbstarctServiceHander(String host, int port) {
		super(host, port);
		
	}

	
	protected  void initChannel(Bootstrap bootstrap){
    	//bootstrap.option(ChannelOption.AUTO_CLOSE, true);
		// 连接时间
    	bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 30000);
		// 长连接
    	bootstrap.option(ChannelOption.SO_KEEPALIVE, true);
    	bootstrap.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
    	bootstrap.handler(new ChannelInitializer<Channel>() {

			@Override
			protected void initChannel(Channel ch) throws Exception {
				doHander(ch);
				
			}
		});
	}
	
	public String getHost() {
		return host;
	}

	public void setHost(String host) {
		this.host = host;
	}

	public int getPort() {
		return port;
	}

	public void setPort(int port) {
		this.port = port;
	}

	public abstract void doHander(Channel ch);
}
